package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * 产地检疫申报  受理  --- 政府端
 * @author niufei
 */
@Data
public class BreedReportSurveyRecord implements Serializable{

    private static final ObjectMapper objectMapper = JsonMapper.nonEmptyMapper().getMapper();

    private static final long serialVersionUID = 7574002055772076476L;

    /**
     * 主键id
     */
    private Long id;

    /**
     * 申报id
     */
    private Long reportId;

    /**
     *  经办人id
     */
    private Long surveyUserId;

    /**
     * 经办人名称
     */
    private String surveyUserName;

    /**
     * 经办人电话
     */
    private String surveyUserMobile;

    /**
     * 处理意见
     */
    private String handleOpinion;

    /**
     * 现场勘查照片 不存数据库
     */
    private Map<String , Map<String , String>> siteSurveyPhotoMap;

    /**
     * 现场勘查照片
     */
    @JsonIgnore
    private String siteSurveyPhotoJson;

    /**
     * 勘查地点经度
     */
    private String surveyLongitude;

    /**
     * 勘查地点纬度
     */
    private String surveyLatitude;

    /**
     * 勘察地址
     */
    private String surveyAddress;

    /**
     * 是否经强制免疫并在有效期内 -1 否 1 是
     */
    private Integer isEffective;

    /**
     * 养殖档案是否符合规定 -1 否 1 是
     */
    private Integer isBreedingArchive;

    /**
     * 是否佩戴规定的畜禽标识 -1 否 1 是
     */
    private Integer hasAnimalIdentify;

    /**
     * 养殖场疫情(六个月内) -1 否 1 是
     */
    private Integer isEpidemic;

    /**
     * 是否在检疫区内 -1 否 1 是
     */
    private Integer isInEpidemic;

    /**
     * 临床检查,-1：否 1：是，
     */
    private Integer examination;

    /**
     * 实验室检测 -1：否 1：是，
     */
    private Integer laboratoryTest;

    /**
     *  检测结果 -1：否 1：是，
     */
    private Integer testResult;

    /**
     * 检疫合格数
     */
    private Integer qualifiedQuantity;

    /**
     * 检疫合格证编号
     */
    private String quarantineCertNumber;

    /**
     * 检疫合格证照片 不存数据库
     */
    private Map<String , Map<String , String>> quarantineCertPhotoMap;

    /**
     * 检疫合格证照片
     */
    @JsonIgnore
    private String quarantineCertPhotoJson;

    /**
     * 检疫不合格数量
     */
    private Integer unqualifiedQuantity;

    /**
     * 一般处理的数量
     */
    private Integer generalTreatmentQuantity;

    /**
     * 一般处理的 0:实验室检测;1:隔离;2:治疗;3:其他
     */
    private Integer generalTreatment;

    /**
     * 无害化处里数量
     */
    private Integer harmlessTreatmentQuantity;

    /**
     * 无害化处理方式1：焚烧,2：化制,3：掩埋,4：发酵,5：其他
     */
    private Integer harmlessTreatment;

    /**
     * 无害化处理ID
     */
    private Long harmlessId;

    /**
     * 无害化处理编号
     */
    private String harmlessNumber;

    /**
     * 官方兽医id
     */
    private Long vetUserId;

    /**
     * 官方兽医名称(就是当前登录人)
     */
    private String vetUserName;

    /**
     * 官方兽医电话
     */
    private String vetUserMobile;

    private String remark;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 更新时间
     */
    private Date updatedAt;


    public void setSiteSurveyPhotoJson(String siteSurveyPhotoJson){
        this.siteSurveyPhotoJson = siteSurveyPhotoJson;

        if(Strings.isNullOrEmpty(siteSurveyPhotoJson)){
            this.siteSurveyPhotoMap = Maps.newHashMap();
        }else {
            try {
                this.siteSurveyPhotoMap = objectMapper.readValue(siteSurveyPhotoJson,  new TypeReference<Map<String , Map<String , String>>>(){});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setSiteSurveyPhotoMap(Map<String , Map<String , String>> siteSurveyPhotoMap){
        this.siteSurveyPhotoMap = siteSurveyPhotoMap;

        if(siteSurveyPhotoMap == null || siteSurveyPhotoMap.isEmpty()){
            this.siteSurveyPhotoJson = null;
        }else {
            try {
                this.siteSurveyPhotoJson = objectMapper.writeValueAsString(siteSurveyPhotoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }

    public void setQuarantineCertPhotoJson(String quarantineCertPhotoJson){
        this.quarantineCertPhotoJson = quarantineCertPhotoJson;

        if(Strings.isNullOrEmpty(siteSurveyPhotoJson)){
            this.quarantineCertPhotoMap = Maps.newHashMap();
        }else {
            try {
                this.quarantineCertPhotoMap = objectMapper.readValue(quarantineCertPhotoJson, new TypeReference<Map<String , Map<String , String>>>(){});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setQuarantineCertPhotoMap(Map<String , Map<String , String>> quarantineCertPhotoMap){
        this.quarantineCertPhotoMap = quarantineCertPhotoMap;

        if(quarantineCertPhotoMap == null || quarantineCertPhotoMap.isEmpty()){
            this.quarantineCertPhotoJson = null;
        }else {
            try {
                this.quarantineCertPhotoJson = objectMapper.writeValueAsString(quarantineCertPhotoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }

}
